<template>
  <div class="sidebar">
    <el-menu
      class="sidebar-el-menu"
      :default-active="navactive"
      :collapse="collapse"
      text-color="#fff"
      style='background: -webkit-linear-gradient(bottom, #3d6df8, #5b8cff)'
      active-text-color="#409EFF"
      unique-opened
      router
    >
      <template v-for="item in routelist">
        <el-menu-item
          :index="item.path"
          :key="item.path"
        >
          <i :class="item.icon"></i>
          <span slot="title">{{ item.sysName }}</span>
        </el-menu-item>
      </template>
    </el-menu>
  </div>
</template>

<script>
import bus from '../common/bus';
import { mapState } from 'vuex';
export default {
    data() {
        return {
            collapse: false,
            navactive: '/main/dashboard'
        };
    },
    computed: {
        ...mapState({
            routelist: (state) => {
                return state.router.routeList;
            }
        }),
        onRoutes() {
            return this.$route.path.replace('/', '');
        }
    },
    created() {
        // 通过 Event Bus 进行组件间通信，来折叠侧边栏
        bus.$on('collapse', (msg) => {
            this.collapse = msg;
            bus.$emit('collapse-content', msg);
        });
    },
    mounted() {
        let url = localStorage.getItem('url');
        // this.$route.push(url)
        this.navactive = url ? url : '/main/dashboard';
    }
};
</script>

<style>
.el-menu .is-active {
    background-color: #fff !important;
    font-size: 19px;
}
.el-menu i {
    color: #fff;
}
.el-menu-item:hover {
    color: #43a7fe !important;
    background-color: #fff;
}
.el-menu-item:hover i {
    color: #43a7fe;
}
</style>
<style scoped>
.sidebar {
    display: block;
    position: absolute;
    left: 0;
    top: 70px;
    bottom: 0;
    overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
    width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
    width: 250px;
}
.sidebar > ul {
    height: 100%;
}
.el-menu-item {
    font-size: 18px;
    height: 60px;
    line-height: 60px;
}
</style>
